package com.mlog.njyjy.ndop.common.domain;

import cn.hutool.core.util.StrUtil;
import com.jfinal.plugin.activerecord.Model;
import com.mlog.njyjy.ndop.common.domain.core.Timeable;
import com.mlog.njyjy.ndop.common.support.Constants;
import com.mlog.njyjy.ndop.share.sql.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author zyz
 * @version v1.0, 2020/8/18
 */
@Data
@Accessors(chain = true)
@Table(prefix = Constants.TBL_PROCESS_PREFIX,
        uniques = {@TableUnique(columns = {"name", "groupId"})},
        comment = "节点表")
public class Node extends Model<Node> implements Timeable {

    @Id
    private Long id;

    @Column(nullable = false, comment = "节点名称")
    private String name;

    @Column(nullable = false, comment = "节点组id")
    private Long groupId;

    @Column(nullable = false, comment = "节点次序")
    private int sequence;

    @Column(nullable = false, comment = "系统负责人")
    private Long contactPersonId;

    @Column(nullable = false, comment = "采集方式")
    private String collectWay;

    @Column(nullable = false, comment = "报警项id集合，逗号分隔")
    private String alarmItemIds = StrUtil.EMPTY;

    @Column(comment = "报警项的附带参数")
    private String addition;

    @Column(nullable = false, comment = "提醒用户群组id集合，逗号分隔")
    private String remindUserGroupId = StrUtil.EMPTY;

    @Column(nullable = false, comment = "报警用户群组id集合，逗号分隔")
    private String alarmUserGroupId = StrUtil.EMPTY;

    @Join(joinedBy = "groupId", mappedBy = "id")
    private NodeGroup nodeGroup;

    @Join(joinedBy = "contactPersonId", mappedBy = "id")
    private ContactPerson contactPerson;

    @Join(joinedBy = "id", mappedBy = "nodeId")
    private MessageCollectItem messageCollectItem;

    @Join(joinedBy = "id", mappedBy = "nodeId")
    private FtpCollectItem ftpCollectItem;

    @Join(joinedBy = "id", mappedBy = "nodeId")
    private ApiCollectItem apiCollectItem;

    @Join(joinedBy = "id", mappedBy = "nodeId")
    private List<BizItem> bizItems;

    @Column(updatable = false)
    private LocalDateTime createAt;

    private LocalDateTime updateAt;

    public ContactPerson getContactPerson(){
        return contactPerson;
    }

    public MessageCollectItem getMessageCollectItem() {
        return messageCollectItem;
    }

    public FtpCollectItem getFtpCollectItem() {
        return ftpCollectItem;
    }

    public ApiCollectItem getApiCollectItem() {
        return apiCollectItem;
    }

    public List<BizItem> getBizItems() {
        return bizItems;
    }
}
